package com.example.demo.proxy;

import org.springframework.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

public class DynamicMain {
    public static void main(String[] args) {
        HouseSubject target = new RealHouseSubject();

        //jdk
        HouseSubject proxy =(HouseSubject) Proxy.newProxyInstance(target.getClass().getClassLoader(),
                new Class[]{HouseSubject.class},new JDKInvocationHandler(target)); //必须是接口 比如HouseSubject.class
        proxy.rent();

        //CGLib
        HouseSubject proxy2 = (HouseSubject) Enhancer.create(HouseSubject.class,new CGLibMethodInterceptor(target));
        proxy2.rent();
    }
}
